﻿// -----------------------------------------------------------------------
// <copyright file="ChessManualHelper.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace JumpJump.Tools
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using JumpJump.Offline;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ChessManualHelper
    {
        public static void GenerateDat(string inFileFolder, string outFileFolder)
        { 
            if (!Directory.Exists(outFileFolder))
            {
                Directory.CreateDirectory(outFileFolder);
            }

            DirectoryInfo dir = new DirectoryInfo(inFileFolder);
            FileInfo[] files = dir.GetFiles();
            string outDatFile = outFileFolder + "\\NewDat.dat";

            Dictionary<string, List<ManualAction>> allManual = new Dictionary<string, List<ManualAction>>();

            foreach (FileInfo file in files)
            {
                if (file.Extension == ".dat")
                {
                    List<ChessManual> manualList = ChessManual.LoadFromDatFile(file.FullName);
                    ChessManual.MergeManualDat(allManual, manualList);
                }
            }

            List<ChessManual> allManualList = new List<ChessManual>();

            foreach(KeyValuePair<string,List<ManualAction>> oneManual in allManual)
            {
                ChessManual cm = new ChessManual(oneManual.Key, oneManual.Value);
                allManualList.Add(cm);
            }

            ChessManual.Serialized(outDatFile, allManualList);
        }
    }
}
